import org.lem.*
import org.lem.auth.ShiroRole
import org.lem.auth.ShiroUser
import org.apache.shiro.crypto.hash.Sha1Hash
import org.apache.shiro.crypto.hash.Sha512Hash

class BootStrap
{

    def init = {
        def adminRole = new ShiroRole(name: "Administrator")
        adminRole.addToPermissions("*:*")
        adminRole.save()

        def volunteerRole = new ShiroRole(name: "Volunteer")
        volunteerRole.addToPermissions("studentLearningActivity:index")
        volunteerRole.addToPermissions("studentLearningActivity:list")
        volunteerRole.addToPermissions("studentLearningActivity:show")
        volunteerRole.addToPermissions("volunteerTeachingActivity:index")
        volunteerRole.addToPermissions("volunteerTeachingActivity:list")
        volunteerRole.addToPermissions("volunteerTeachingActivity:show")
        volunteerRole.addToPermissions("volunteerPosition:list")
        volunteerRole.addToPermissions("volunteerPosition:show")
        volunteerRole.save()

        def dataEntry1Role = new ShiroRole(name: "Data Entry L1")
        dataEntry1Role.addToPermissions("student")
        dataEntry1Role.addToPermissions("studentLearningActivity")
        dataEntry1Role.addToPermissions("volunteerHours")
        dataEntry1Role.addToPermissions("studentLearningSkill")
        dataEntry1Role.addToPermissions("studentPreference")
        dataEntry1Role.save()

        def dataEntry2Role = new ShiroRole(name: "Data Entry L2")
        dataEntry2Role.addToPermissions("volunteer")
        dataEntry2Role.addToPermissions("volunteerDaysTime")
        dataEntry2Role.addToPermissions("volunteerPosition")
        dataEntry2Role.addToPermissions("volunteerSkill")
        dataEntry2Role.addToPermissions("volunteerTeachingActivity")
        dataEntry2Role.addToPermissions("teachingAssignment")
        volunteerRole.permissions.each {
            dataEntry2Role.addToPermissions(it)
        }
        dataEntry1Role.permissions.each {
            dataEntry2Role.addToPermissions(it)
        }
        dataEntry2Role.save()

        def adminUser1 = new ShiroUser(username: 'admin', passwordHash: new Sha512Hash("admin").toHex())
        adminUser1.addToRoles(adminRole)
        adminUser1.save()

    }
    def destroy = {
    }
} 